import http from '@/utils/http'

const BASE_URL = '/asset/part/records'

export interface PartRecordsResp {
  id: string
  name: string
  categoryId: string
  code: string
  producerId: string
  specification: string
  sn: string
  price: string
  purchaseDate: string
  expireDate: string
  depreciationRuleId: string
  status: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}
export interface PartRecordsDetailResp {
  id: string
  name: string
  categoryId: string
  code: string
  producerId: string
  specification: string
  sn: string
  price: string
  purchaseDate: string
  expireDate: string
  depreciationRuleId: string
  status: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}
export interface PartRecordsQuery {
  name: string | undefined
  sort: Array<string>
}
export interface PartRecordsPageQuery extends PartRecordsQuery, PageQuery {}

/** @desc 查询配件列表 */
export function listPartRecords(query: PartRecordsPageQuery) {
  return http.get<PageRes<PartRecordsResp[]>>(BASE_URL, query)
}

/** @desc 查询配件详情 */
export function getPartRecords(id: string) {
  return http.get<PartRecordsDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增配件 */
export function addPartRecords(data: any) {
  return http.post(BASE_URL, data)
}

/** @desc 修改配件 */
export function updatePartRecords(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除配件 */
export function deletePartRecords(id: string) {
  return http.del(BASE_URL, { ids: [id] })
}

/** @desc 导出配件 */
export function exportPartRecords(query: PartRecordsQuery) {
  return http.download(`${BASE_URL}/export`, query)
}
